import pageination from '../../components/pageination/pageination.vue'
export default {
	data() {
		return {
			//数据
			total: 0, //总条数
			page: 1, //当前页
			size: 10, //每页显示条数
      search: '',
      auditModel: false,
      projectDetailsModelShow: false,
      auditObj: {}, //审核对象
      project: {},
      FileUpload: [],
      projectList: [],
      closureAuditMsg:false,//判断不通过内容是否输入
		}
	},
	components: {
		pageination
	},
	created() { //调用方法
    //初始化分页信息
    this.searchTodo();
	},
	mounted() {},
	methods: { //写函数方法
		//页码切换执行方法
		pageFn: function(val, pid) {
			this.page = parseInt(val);
			//此处调列表数据接口
      this.searchTodo();
		},
		/**返回子组件用户选择的一页显示条数**/
		obtainChild: function(data) {
			this.row = data;
		},
    //项目详情模态框
    projectDetails: function(projectId) {
      this.project = {};
		  this.getProject(projectId);
      this.projectDetailsModelShow = true;
    },
    auditModelShow: function(projectId) {
      this.auditObj = {};
      this.FileUpload = [];
      this.auditObj.id = projectId;
		  this.auditModel = true;
    },
    auditData: function() {
      let auditObj = this.auditObj;
      this.closureAuditMsg=true;
      if (auditObj.screenAuditMsg == null || auditObj.screenAuditMsg.length == 0 || auditObj.screenAuditMsg.length > 100) {
        return;
      }
		  this.auditProject(auditObj.id, 3, auditObj.screenAuditMsg, auditObj.screenAuditEnclosureUrl);
		  this.auditModel = false;
		   this.closureAuditMsg=false;
    },
    //关闭模态框
    closeModel: function() {
      this.projectDetailsModelShow = false;
      this.auditModel = false;
      this.closureAuditMsg=false;
    },
    //预览
    preview: function(url) {
		  if (url == null || url == "") {
        layer.msg("暂无附件！");
      } else {
        window.open(this.urls.baseUrl + url);
      }
    },
    //搜索数据列表
    searchTodo: function() {
      let that = this;
      that.$post(
        that.urls.getProjectScreenPageInfo,
        {"pageNum": that.page,"pageSize": that.size,"search": that.search}
      )
      .then(function(res) {
        if(res.success) {
          that.projectList = res.pageInfo.list;
          that.total = res.pageInfo.total;
          that.page = res.pageInfo.pageNum;
        }
      })
    },
    //审核状态
    auditStatus: function(status) {
		  if (status != null) {
        switch (status) {
          case 0:
            return "暂存";
          case 1:
            return "未审核";
          case 2:
            return "筛选成功";
          case 3:
            return "筛选失败";
        }
      }
    },
    //删除附件
    deleteEnclosure: function() {
      this.FileUpload = [];
      this.auditObj.screenAuditEnclosureUrl = "";
    },
    /**文件上传js**/
    idFrontImg: function(event) {
      var that = this;
      var file = event.currentTarget.files[0];
      if (!that.fileGlobalFilter(file)) {
        return;
      }
      let formData = new FormData();
      formData.append('fileNames', file);
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data;boundary = ' + new Date().getTime()
        }
      };
      that.$post(
        that.urls.upload,
        formData,
        config
      )
      .then(function(res) {
          if (res.success) {
            let fileInfo = res.data[0];
            that.auditObj.screenAuditEnclosureUrl = fileInfo.url;
            that.FileUpload = [that.getFileName(fileInfo.url)];
          }
        })
    },
    //审核
    auditProject: function(id, screenAuditStatus, screenAuditMsg, screenAuditEnclosureUrl) {
      if (id == null || screenAuditStatus == null) {
        return;
      }
		  let that = this;
      that.$post(
        that.urls.auditScreenProject,
        {"id": id, "screenAuditStatus": screenAuditStatus,"screenAuditMsg": screenAuditMsg, "screenAuditEnclosureUrl": screenAuditEnclosureUrl}
      )
      .then(function(res) {
        let msg = "";
        if(res.success) {
          msg = '审核成功！';
          //重新渲染数据
          that.searchTodo();
        } else {
          msg = '审核失败！';
        }
        layer.msg(msg, {
          time: 3000, //3s后自动关闭
        });
      })
    },
    //获取项目
    getProject: function(id) {
      let that = this;
      if (id != null) {
        that.$post(
          that.urls.getProjectInfo, {
            "id": id
          }
        )
        .then(function(res) {
          if(res.success) {
            that.project = res.data;
          }
        })
      }
    },
	}
}
